package com.happy.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.happy.dao.AdminMapper;
import com.happy.entity.AdminEntity;
import com.happy.service.IAdminService;
import com.happy.util.CommonUtil;
import com.happy.util.StateEnum;
import com.happy.util.StateException;
import org.springframework.stereotype.Service;

@Service
public class AdminServiceImpl extends ServiceImpl<AdminMapper, AdminEntity> implements IAdminService {


    @Override
    public AdminEntity querySingle ( AdminEntity adminEntity ) {
        if ( adminEntity == null ) {
            throw new StateException ( StateEnum.REQUEST_PARAM_EXCE );
        }
        AdminEntity admin = baseMapper.selectOne ( new QueryWrapper<AdminEntity> ().eq ( "phone", adminEntity.getPhone () ).eq ( "password", adminEntity.getPassword () ) );
        if ( admin != null ) {
            admin.setToken ( CommonUtil.getToken () );
            return admin;
        }
        return null;
    }
}
